package com.wrupple.muba.common.shared;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.JsArrayNumber;
import com.google.gwt.core.client.JsArrayString;
import com.wrupple.muba.common.client.JSOHelper;
import com.wrupple.muba.common.domain.FilterCriteria;
import com.wrupple.muba.common.domain.FilterData;

public class FilterDataUtils {

	public static FilterData createSingleFieldFilter(String field, String value) {
		FilterData regreso = new FilterData();
		regreso.setConstrained(false);
		Map<String, List<FilterCriteria>> filters = new HashMap<String, List<FilterCriteria>>(
				1);
		List<FilterCriteria> criterias = new ArrayList<FilterCriteria>(1);
		FilterCriteria product = new FilterCriteria();
		product.setOperator(FilterData.EQUALS);
		product.setValue(value);
		criterias.add(product);
		filters.put(field, criterias);
		regreso.setFilters(filters);
		return regreso;
	}
	
	public static FilterData createSingleFieldFilter(String field, List<String> values) {
		FilterData regreso = new FilterData();
		regreso.setConstrained(false);
		Map<String, List<FilterCriteria>> filters = new HashMap<String, List<FilterCriteria>>(
				1);
		List<FilterCriteria> criterias = new ArrayList<FilterCriteria>(1);
		FilterCriteria product = new FilterCriteria();
		product.setOperator(FilterData.EQUALS);
		product.setValues(values);
		criterias.add(product);
		filters.put(field, criterias);
		regreso.setFilters(filters);
		return regreso;
	}

	public static FilterData createSingleFieldFilter(String field,
			JsArrayString values) {
		FilterData regreso = new FilterData();
		regreso.setConstrained(false);
		Map<String, List<FilterCriteria>> filters = new HashMap<String, List<FilterCriteria>>(
				1);
		List<FilterCriteria> criterias = new ArrayList<FilterCriteria>(1);
		FilterCriteria product = new FilterCriteria();
		product.setOperator(FilterData.EQUALS);
		product.setValues(JSOHelper.asStringList(values));
		criterias.add(product);
		filters.put(field, criterias);
		regreso.setFilters(filters);
		return regreso;
	}

	public static FilterData createSingleFieldFilter(String field,
			JsArrayNumber values) {
		FilterData regreso = new FilterData();
		regreso.setConstrained(false);
		Map<String, List<FilterCriteria>> filters = new HashMap<String, List<FilterCriteria>>(
				1);
		List<FilterCriteria> criterias = new ArrayList<FilterCriteria>(1);
		FilterCriteria product = new FilterCriteria();
		product.setOperator(FilterData.EQUALS);
		product.setValues(JSOHelper.asStringList(values));
		criterias.add(product);
		filters.put(field, criterias);
		regreso.setFilters(filters);
		return regreso;
		
	}

}
